package com.cn.ycy.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("test")
public class  TestController {

  Logger logger = LoggerFactory.getLogger(TestController.class);

  @GetMapping(value = "/get")
  @ResponseBody
  public String load(HttpServletRequest request) {
    logger.info("RequestBody {}", request);
    return "欢迎使用springboot-docker应用" + "InetAddress.getLocalHost().getHostName()";
  }

  @GetMapping(value = "/oom")
  @ResponseBody
  public String oom(HttpServletRequest request) {
    int i = 0;
    try {
//      for (int j = 0; j < 1000; j++) {
//        byte[] arr = new byte[1024*1000];
//      }
      byte[] arr1 = new byte[1024*1000];
      byte[] arr2 = new byte[1024*1000];
      byte[] arr3 = new byte[1024*1000];
      byte[] arr4 = new byte[1024*1000*8];
      while (true) {
        System.out.println(".");
        Thread.sleep(1000);
      }
    } catch (Throwable e) {
      e.printStackTrace();
      System.out.println("结束");
    }
    return "欢迎使用springboot-docker应用";
  }

  public static final int BUFFER_SIZE = 4096;

}
